package b.g.b.h.l;

import b.d.i;
import b.g.b.h.d;
import b.g.b.h.e;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;

/* compiled from: WidgetGroup */
public class n {
    public static int f;
    public ArrayList<d> a = new ArrayList();
    public int b = -1;
    public int c = 0;
    public ArrayList<a> d = null;
    public int e = -1;

    /* compiled from: WidgetGroup */
    public class a {
        public a(n nVar, d dVar, b.g.b.d dVar2, int i) {
            WeakReference weakReference = new WeakReference(dVar);
            dVar2.o(dVar.D);
            dVar2.o(dVar.E);
            dVar2.o(dVar.F);
            dVar2.o(dVar.G);
            dVar2.o(dVar.H);
        }
    }

    public n(int i) {
        int i2 = f;
        f = i2 + 1;
        this.b = i2;
        this.c = i;
    }

    public boolean a(d dVar) {
        if (this.a.contains(dVar)) {
            return false;
        }
        this.a.add(dVar);
        return true;
    }

    public void b(ArrayList<n> arrayList) {
        int size = this.a.size();
        if (this.e != -1 && size > 0) {
            for (int i = 0; i < arrayList.size(); i++) {
                n nVar = (n) arrayList.get(i);
                if (this.e == nVar.b) {
                    d(this.c, nVar);
                }
            }
        }
        if (size == 0) {
            arrayList.remove(this);
        }
    }

    public int c(b.g.b.d dVar, int i) {
        int i2 = 0;
        if (this.a.size() == 0) {
            return 0;
        }
        int o;
        ArrayList arrayList = this.a;
        e eVar = (e) ((d) arrayList.get(0)).P;
        dVar.u();
        eVar.d(dVar, false);
        for (int i3 = 0; i3 < arrayList.size(); i3++) {
            ((d) arrayList.get(i3)).d(dVar, false);
        }
        if (i == 0 && eVar.t0 > 0) {
            i.a(eVar, dVar, arrayList, 0);
        }
        if (i == 1 && eVar.u0 > 0) {
            i.a(eVar, dVar, arrayList, 1);
        }
        try {
            dVar.q();
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.d = new ArrayList();
        while (i2 < arrayList.size()) {
            this.d.add(new a(this, (d) arrayList.get(i2), dVar, i));
            i2++;
        }
        if (i == 0) {
            i = dVar.o(eVar.D);
            o = dVar.o(eVar.F);
            dVar.u();
        } else {
            i = dVar.o(eVar.E);
            o = dVar.o(eVar.G);
            dVar.u();
        }
        return o - i;
    }

    public void d(int i, n nVar) {
        Iterator it = this.a.iterator();
        while (it.hasNext()) {
            d dVar = (d) it.next();
            nVar.a(dVar);
            if (i == 0) {
                dVar.j0 = nVar.b;
            } else {
                dVar.k0 = nVar.b;
            }
        }
        this.e = nVar.b;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        int i = this.c;
        String str = i == 0 ? "Horizontal" : i == 1 ? "Vertical" : i == 2 ? "Both" : "Unknown";
        stringBuilder.append(str);
        stringBuilder.append(" [");
        String c = c.b.a.a.a.c(stringBuilder, this.b, "] <");
        Iterator it = this.a.iterator();
        while (it.hasNext()) {
            d dVar = (d) it.next();
            stringBuilder = c.b.a.a.a.i(c, " ");
            stringBuilder.append(dVar.d0);
            c = stringBuilder.toString();
        }
        return c.b.a.a.a.D(c, " >");
    }
}
